# -*- codeing = utf-8 -*-
# @Time : 2021/2/25 14:02
# @Atuthor: 朱朱
# @File: 086计算一段代码的执行时间.py
# @Software: PyCharm
import time

# start = time.time()
# print(start)
# x = 0
# for i in range(1,111111111):
#     x+=i
# print(x)
# end = time.time()
#
# print(f'代码运行了{end-start}秒')

# 优化计算时间代码,形成函数,方便其他代码调用
def cal_time(fn):
    start = time.time()
    fn()
    end = time.time()
    print(f'代码运行耗时{end-start}')

def demo():
    x = 0
    for i in range(1,11111111):
        x+=i
    print(x)

def foo():
    print('我要开始睡觉了')
    time.sleep(3)
    print('我已经睡好了')

cal_time(demo)
print('---------------------')
cal_time(foo)